package com.atguigu.gulimall.search.controller;


import com.atguigu.common.to.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.atguigu.common.exception.CodeEnum.VALID_EXCEPTION;

@RequestMapping("/es")
@RestController
public class ElasticSearchController {

    @Autowired
    private ElasticSearchService elasticSearchService;

    @RequestMapping("/save/product")
    public R saveProductInfo(@RequestBody List<SkuEsModel> esModels){
        boolean b = elasticSearchService.saveProduct(esModels);
        if (b){
            return R.ok();
        }else {
            return R.error(VALID_EXCEPTION.getCode(),"上架失败");
        }

    }
}
